﻿using AnQinFrameWorkAPI.Entity.SystemCore.DTO.CodeRule;
using AnQinFrameWorkAPI.Entity.SystemCore.View.CodeRule;
using AnQinFrameWorkAPI.Service.SystemCore;
using FrameWork.Entity;
using Microsoft.AspNetCore.Mvc;

namespace AnQinFrameWorkAPI.Controllers.SystemCore;

/// <summary>
///     编码规则API
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = "SystemCore")]
public class CodeRuleController : ControllerBase
{
    //编码规则接口
    private readonly CodeRuleService _codeRuleService;

    //构造注入
    public CodeRuleController(CodeRuleService codeRuleService)
    {
        _codeRuleService = codeRuleService;
    }

    /// <summary>
    ///     获取编码规则列表
    /// </summary>
    [ProducesResponseType(typeof(CodeRuleView), 200)]
    [HttpGet]
    public async Task<IActionResult> GetCodeRuleList([FromQuery] CodeRuleSearchDTO codeRuleSearchDTO)
    {
        var response = await _codeRuleService.GetCodeRuleList(codeRuleSearchDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     新增编码规则
    /// </summary>
    /// <params name="codeRuleAddDTO"></params>
    [HttpPost]
    public async Task<IActionResult> AddCodeRule([FromBody] CodeRuleAddDTO codeRuleAddDTO)
    {
        var response = await _codeRuleService.AddCodeRule(codeRuleAddDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     编辑编码规则
    /// </summary>
    /// <params name="codeRuleUpdateDTO"></params>
    [HttpPut]
    public async Task<IActionResult> PutCodeRule([FromBody] CodeRuleUpdateDTO codeRuleUpdateDTO)
    {
        var response = await _codeRuleService.PutCodeRule(codeRuleUpdateDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     删除编码规则
    /// </summary>
    [HttpDelete]
    public async Task<IActionResult> DeleteCodeRule([FromBody] SingleIdDTO deleteDTO)
    {
        var response = await _codeRuleService.DeleteCodeRule(deleteDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     获取编码规则详情
    /// </summary>
    [ProducesResponseType(typeof(CodeRuleDetailView), 200)]
    [HttpGet("Detail")]
    public async Task<IActionResult> DeleteArrayCodeRule([FromQuery] SingleIdDTO singleIdDTO)
    {
        var response = await _codeRuleService.GetCodeRuleDetail(singleIdDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     批量删除编码规则
    /// </summary>
    /// <param name="idArrayDTO"></param>
    [HttpPost("DeleteMulti")]
    public async Task<IActionResult> DeleteArrayCodeRule([FromBody] IdArrayDTO idArrayDTO)
    {
        var response = await _codeRuleService.DeleteArrayCodeRule(idArrayDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     编码规则表 - 获取编码
    /// </summary>
    /// <param name="Id">编码规则表Id</param>
    [HttpGet("GetCode")]
    public async Task<IActionResult> GetCode([FromQuery] string Id)
    {
        var response = await _codeRuleService.GetNewCode(Id);
        return StatusCode(response.Status, response);
    }
}